package com.wzf;

import com.mysql.cj.log.Log;
import lombok.extern.slf4j.Slf4j;

import javax.jws.soap.SOAPBinding;
import java.io.*;

/**
 *  序列化，生成唯一的UID
 * @Author:wzf
 * @Data:2022/2/17
 * @Version:1.0
 */
@Slf4j
public class SerializableTest {


  public static void main(String[] args) throws IOException {
    File file=new File("user.txt");
    ObjectOutputStream  outputStream=new ObjectOutputStream(new FileOutputStream(file));
    try {
      User user=new User(1,"张三");
      outputStream.writeObject(user);
    } catch (FileNotFoundException e) {
        log.debug("文件输出失败" + e);
    } finally {
        outputStream.close();
    }

    ReaderUser();
  }

  public static void ReaderUser() throws IOException{
    File file=new File("user.txt");
    ObjectInputStream  inputStream = inputStream = new ObjectInputStream(new FileInputStream(file));
    try {
      User user =(User) inputStream.readObject();
      System.out.println(user);
    } catch (ClassNotFoundException e) {
      log.debug("当前类没有找到" + e);
    }
    finally {
      inputStream.close();

    }

  }




}
